<template>

        <el-card style="width: 500px;" size="small">
          <el-form>
            <el-upload
              style="text-align:center"
              class="avatar-uploader"
              action="http://124.223.93.49:8081/file/upload"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
            >
              <img v-if="form.avatar" :src="form.avatar" class="avatar" style="width: 150px;height: 150px;" />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <el-form-item label="用户名"  >
              <el-input v-model="user.username" auto-complete="off" disabled></el-input>
            </el-form-item>
            <el-form-item label="姓名">
              <el-input v-model="form.nickname" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="班级">
              <el-input v-model="form.className" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="创建时间">
              <el-input v-model="form.createTime" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="save">确认修改</el-button>
            </el-form-item>
          </el-form>
        </el-card>
   
</template>
<script>
import request from "@/utils/request";


export default {
  data() {
    return {
      
      name:JSON.parse(localStorage.getItem("user")).username,
      form: {},
      user: localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user"))
        : {},
    };
  },
  methods: {
    async load() {
     /*  request.get("user/person/" + this.user.username).then((res) => {
        this.form = res.data;
      }); */
   /*    let res= await request.get("user/person/" + this.user.username);
      console.log(res);
      this.form = res.data;
      return res.data; */
      return (await request.get("user/person/"+this.user.username)).data
    },
    handleAvatarSuccess(res){
      this.form.avatar=res
    },
    save() {
      this.request.post("/user/save", this.form,{params:{name:this.name}}).then((res) => {
        if (res) {
          this.$message.success("成功");
        /*   let user=this.load();
          user.token=JSON.parse(localStorage.getItem('user')).token;
          localStorage.setItem("user",JSON.stringify(user)); */
         /*  this.load().then(res=>{
              res.token=JSON.parse(localStorage.getItem('user')).token;
              localStorage.setItem("user",JSON.stringify(res));
          }) */
          this.$emit("refreshUser");
        } else {
          this.$message.error("失败");
          
        }
       
      });
    },
  },
  created() {
    //请求分页数据
  /*   this.load(); */
    this.load().then(res=>{
        this.form=res
    })
  },
};
</script>
<style>

</style>